package com.test1;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Paint;
import android.graphics.Rect;

import java.util.ArrayList;
import java.util.HashMap;

public final class ResourceManager{
	private static HashMap< Integer, Bitmap > res = new HashMap< Integer, Bitmap >();
	private static ArrayList< Rect > rs = new ArrayList< Rect>();
	private static ArrayList< Paint > ps = new ArrayList< Paint >(); 
	public static Bitmap loadResource( int id ){
		Bitmap bitmap = BitmapFactory.decodeResource( Game.currentactivity.getResources(), id );
		res.put( id, bitmap);
		return bitmap;
	}
	
	public static Bitmap getResource( int id ){
		Bitmap r = res.get( id );
		if( r != null )
			return r;
		return loadResource( id );
	}
	
	public static Rect popRect(){
		if( rs.size() > 0 ){
			return  rs.remove( 0 );
		}
		return new Rect();
	}
	
	public static void pushRect( Rect rect ){
		rs.add( rect );
	}
	
	public static Paint popPaint(){
		if( ps.size() > 0 ){
			return  ps.remove( 0 );
		}
		return new Paint();
	}
	
	public static void pushPaint( Paint paint ){
		ps.add( paint );
	}
}